<?php
/**
 * Created by PhpStorm.
 * User: 魏爷
 * Date: 2016/5/31
 * Time: 9:44
 */

namespace Home\Model;


class BuyBookModel extends BaseModel
{
    // 数据表名（不包含表前缀）
    protected $tableName        =   'buybook';

    /**
     * 根据用户ID查询交易表的所有信息
     * @param Integer $u_id 用户ID
     * @return array()
    **/
    public function getBookBuyInfo($u_id){
        return $this->where("u_id=$u_id")->order('buybook_id DESC')->select();
    }
    /**
     * 订单提交
     * @param Integer $u_id 用户ID
     * @param Integer $buy_type 送货类型
     * @param String $real_name 真实姓名
     * @param String $u_address 送货地址
     * @param Integer $u_tel 联系电话
     * @param String $book_name 图书名称
     * @param Integer $book_price 图书价格
     * @param String $bank 银行
     * @param Integer $bank_number 银行卡账号
     * @return boolean
    **/
    public function buyInfoAdd($u_id,$buy_type,$real_name,$u_address,$u_tel,$book_name,$book_price,$bank,$bank_number){
        if($buy_type==1){
            $data['u_id']=$u_id;
            $data['buy_type']=$buy_type;
            $data['real_name']=$real_name;
            $data['u_address']=$u_address;
            $data['u_tel']=$u_tel;
            $data['book_name']=$book_name;
            $data['book_price']=$book_price;
            $data['book_status']=1;
            $data['buybook_time']=time();
            $res=$this->add($data);
            if($res>0){
                return true;
            }else{
                return false;
            }
        }else{
            $data['u_id']=$u_id;
            $data['buy_type']=$buy_type;
            $data['real_name']=$real_name;
            $data['u_address']=$u_address;
            $data['u_tel']=$u_tel;
            $data['book_name']=$book_name;
            $data['book_price']=$book_price;
            $data['bank']=$bank;
            $data['book_status']=1;
            $data['bank_number']=$bank_number;
            $data['buybook_time']=time();
            $res=$this->add($data);
            if($res>0){
                return true;
            }else{
                return false;
            }
        }
    }

}